home *** CD-ROM | disk | FTP | other *** search
- Path: gail.ripco.com!mambuhl
- From: mambuhl@ripco.com (Martin Ambuhl)
- Newsgroups: comp.lang.c
- Subject: Re: how can an int data t
- Date: 7 Mar 1996 07:56:17 GMT
- Organization: Ripco Communications, Inc.
- Message-ID: <4hm4r1$gtp@gail.ripco.com>
- NNTP-Posting-Host: cook.ripco.com
-
- Howard Salmon <captarm@azstarnet.com>
- in <4hg2si$irt@news.azstarnet.com> asks:
-
- >I thought that the int data type could only accept integer data;
- >however, the example listed below (taken from Dave Mark's book "Learn C
- >on the Macintosh") shows an int variable ("done") accepting character
- >data (i.e. "FALSE")....
-
- [snip]
-
- >#include <stdio.h>
-
- >main()
- >{
- > int startingPoint, candidate, i;
- > int done, foundFactor;
-
- > done = FALSE;
-
- There are two different misperceptions that you may have. The choice
- between them depends on what you mean by `character data'. I suspect
- that you have in mind the first below; if you were a little more
- experienced as a C programmer, I would suspect the second.
-
- 1) You may think FALSE is a string. "FALSE" would be a string, FALSE is
- an identifier. The problem with FALSE is that it has no value. I guess
- the Macintosh compiler Dave Mark that assumes improperly gives FALSE a
- value in stdio.h.
-
- This is probably done via macros:
- #define FALSE 0
- #define TRUE 1
- or enums:
- typedef enum {FALSE, TRUE} BOOLEAN;
- In either case, not only should these not be in a system header and are
- (in this code) otherwise undefined, but also can lead to logical errors
- if not used with care.
-
- 2) You may think that FALSE is actually "character data", e.g.
- const char FALSE = 0;
- rather than a string. An assignment of a char to an int is quite legal:
- char is an integral type, and int is another. The char value is
- promoted to an int and assigned without any problems. Whether char is
- signed or unsigned raises different questions when the MSB=1.
-
- --
- * Martin Ambuhl net: mambuhl@ripco.com
- * Chicago, IL (USA)
-